from BeautifulSoup import BeautifulSoup
import re
import Tools

class ExtractList :
#    def get(self, site, src):
#        dictt = {}
#        soup = BeautifulSoup(''.join(src))
#        #soup = soup.findAll(attrs={'class' : 'f14 fbold'})
#        soup = soup.findAll(attrs=site.attrs)
#        for s in soup :
#            title = s.renderContents().strip()
#            p = re.compile('\s*<.*?>\s*')
#            title = p.sub('', title)
#            dictt[title] = site.homeUrl + s['href']
#        return dictt
    
    def get(self, site, src):
        dictt = {}
        soup = BeautifulSoup(''.join(src))
        soup = soup.findAll(attrs=site.attrs)
        for s in soup :
            title = None
            exec "title = str(s" + site.soupHtm + ").strip()"
            p = re.compile('\s*<.*?>\s*')
            title = p.sub('', title)
            title = Tools.decodeHtmlentities(title)
            url = None
            exec "url = s" + site.soupHtm + "['href']"
            if "//" in str(url) :
                dictt[title] = url
            else :
                dictt[title] = site.homeUrl + url
        return dictt
        
      
